'virtual_size': 100 * 1024,
'sector_size': 1024,
'type': 'system',
- 'parent': '',
+ 'parent': '',
+ 'SR_name': 'QCoW',
'sharable': False,
'read_only': False,
}
'driver': 'paravirtualised',
}
+local_vdi_cfg = {
+ 'name_label': 'gentoo.amd64.img',
+ 'name_description': '',
+ 'uri': 'file:/root/gentoo.amd64.img',
+ 'virtual_size': 0,
+ 'sector_size': 0,
+ 'type': 'system',
+ 'parent': '',
+ 'SR_name': 'Local',
+ 'sharable': False,
+ 'read_only': False,
+}
+
local_vbd_cfg = {
'VDI': '',
'VM': '',
'mode': 'RW',
'type': 'disk',
'driver': 'paravirtualised',
- 'image': 'file:/root/gentoo.amd64.img'
}
vif_cfg = {
server, session = connect()
vm_uuid = None
vdi_uuid = None
+ local_vdi_uuid = None
local_vbd_uuid = None
vbd_uuid = None
vif_uuid = None
vm_names.append(vm_record['name_label'])
# Get default SR
- sr_list = execute(server, 'SR.get_by_name_label', (session, 'Local'))
+ sr_list = execute(server, 'SR.get_by_name_label', (session,
+ vdi_cfg['SR_name']))
sr_uuid = sr_list[0]
+ local_sr_list = execute(server, 'SR.get_by_name_label',
+ (session, local_vdi_cfg['SR_name']))
+ local_sr_uuid = local_sr_list[0]
+
# Get default network
net_list = execute(server, 'network.get_all', (session,))
net_uuid = net_list[0]
vbd_cfg['VM'] = vm_uuid
vbd_cfg['VDI'] = vdi_uuid
vbd_uuid = execute(server, 'VBD.create', (session, vbd_cfg))
-
+
+ # Create a new VDI (Local)
+ local_vdi_cfg['SR'] = local_sr_uuid
+ local_vdi_uuid = execute(server, 'VDI.create',
+ (session, local_vdi_cfg))
+
# Create a new VBD (Local)
local_vbd_cfg['VM'] = vm_uuid
- local_vbd_cfg['VDI'] = ''
+ local_vbd_cfg['VDI'] = local_vdi_uuid
local_vbd_uuid = execute(server, 'VBD.create',
(session, local_vbd_cfg))
-
+
# Create a new VIF
vif_cfg['network'] = net_uuid
vif_cfg['VM'] = vm_uuid
time.sleep(30)
- print 'Suspending VM..'
- execute(server, 'VM.suspend', (session, vm_uuid))
- print 'Suspended VM.'
- time.sleep(5)
- print 'Resuming VM ...'
- execute(server, 'VM.resume', (session, vm_uuid, False))
- print 'Resumed VM.'
+ test_suspend = True
+ if test_suspend:
+ print 'Suspending VM..'
+ execute(server, 'VM.suspend', (session, vm_uuid))
+ print 'Suspended VM.'
+ time.sleep(5)
+ print 'Resuming VM ...'
+ execute(server, 'VM.resume', (session, vm_uuid, False))
+ print 'Resumed VM.'
# Wait for user to say we're good to shut it down
while True:
# Clean up
if vif_uuid:
execute(server, 'VIF.destroy', (session, vif_uuid))
+
if local_vbd_uuid:
execute(server, 'VBD.destroy', (session, local_vbd_uuid))
+ if local_vdi_uuid:
+ execute(server, 'VDI.destroy', (session, local_vdi_uuid))
+
if vbd_uuid:
execute(server, 'VBD.destroy', (session, vbd_uuid))
if vdi_uuid:
execute(server, 'VDI.destroy', (session, vdi_uuid))
+
if vm_uuid:
try:
execute(server, 'VM.hard_shutdown', (session, vm_uuid))
'%(type)-10s'
VDI_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(virtual_size)-8s '\
'%(sector_size)-8s'
-VBD_LIST_FORMAT = '%(device)-6s %(uuid)-36s %(VDI)-8s %(image)-8s'
+VBD_LIST_FORMAT = '%(device)-6s %(uuid)-36s %(VDI)-8s'
TASK_LIST_FORMAT = '%(name_label)-18s %(uuid)-36s %(status)-8s %(progress)-4s'
VIF_LIST_FORMAT = '%(name)-8s %(device)-7s %(uuid)-36s %(MAC)-10s'
'action': 'store_true'})],
'vdi-create': [(('--name-label',), {'help': 'Name for VDI'}),
- (('--description',), {'help': 'Description for VDI'}),
+ (('--name-description',), {'help': 'Description for VDI'}),
(('--sector-size',), {'type': 'int',
- 'help': 'Sector size'}),
+ 'help': 'Sector size',
+ 'default': 0}),
(('--virtual-size',), {'type': 'int',
+ 'default': 0,
'help': 'Size of VDI in sectors'}),
(('--type',), {'choices': ['system', 'user', 'ephemeral'],
+ 'default': 'system',
'help': 'VDI type'}),
(('--sharable',), {'action': 'store_true',
'help': 'VDI sharable'}),
(('--read-only',), {'action': 'store_true',
- 'help': 'Read only'})],
+ 'help': 'Read only'}),
+ (('--sr',), {})],
'vbd-create': [(('--VDI',), {'help': 'UUID of VDI to attach to.'}),
(('--mode',), {'choices': ['RO', 'RW'],
'help': 'device mount mode'}),
(('--driver',), {'choices':['paravirtualised', 'ioemu'],
'help': 'Driver for VBD'}),
- (('--device',), {'help': 'Device name on guest domain'}),
- (('--image',), {'help': 'Location of drive image.'})]
+ (('--device',), {'help': 'Device name on guest domain'})]
}
print VBD_LIST_FORMAT % {'device': 'Device',
'uuid' : 'UUID',
- 'VDI': 'VDI',
- 'image': 'Image'}
+ 'VDI': 'VDI'}
for vbd in vbds:
vbd_struct = execute(server, 'VBD.get_record', (session, vbd))
cfg[opt] = val
server, session = connect()
- srs = execute(server, 'SR.get_all', (session,))
+ srs = []
+ if cfg.get('SR'):
+ srs = execute(server, 'SR.get_by_name_label', (session, cfg['SR']))
+ else:
+ srs = execute(server, 'SR.get_all', (session,))
+
sr = srs[0]
cfg['SR'] = sr